<div class="wrapper-bz-page">
    <div class="wrapper-bz-body" >
        <div class="column-block block-left" style="width:390px;">
            <div class="column-title">电影</div>
            <div class="column-content">
                <div class="column-filter">
                    <div class="common-search-box">
                        <input style="width:120px"  id="search_input_lib_movie_in_m78" />
                    </div>
                </div>
                <div class="column-datagrid">
                    <table id="table_lib_movie_in_m78" style="width:100%;height:100%"></table>
                </div>
            </div>
        </div>
        <div class="column-block block" style="left:400px; width:600px;">
            <div class="column-title">英文字幕</div>
            <div class="column-content">
                <div class="column-filter">
                    <div class="common-search-box">
                        <input style="width:120px"  id="search_input_lib_movie_subtitle_en_in_m78" />
                    </div>
                </div>
                <div class="column-datagrid">
                    <table id="table_lib_movie_subtitle_en_in_m78" style="width:100%;height:100%"></table>
                </div>
            </div>
        </div>
        <div class="column-block block-right" style="left:1010px;">
            <div class="column-title">中文字幕</div>
            <div class="column-content">
                <div class="column-filter">
                    <div class="common-search-box">
                        <input style="width:120px"  id="search_input_lib_movie_subtitle_cn_in_m78" />
                    </div>
                </div>
                <div class="column-datagrid">
                    <table id="table_lib_movie_subtitle_cn_in_m78" style="width:100%;height:100%"></table>
                </div>
            </div>
        </div>
    </div>
</div>
<div id="dialog_add_lib_movie_subtitle_in_m78"></div>
<div id="dialog_edit_lib_movie_subtitle_in_m78"></div>
<div id="dialog_add_lib_movie_word_in_m78"></div>

<script>
    $(function(){
        var subject_1 = "lib_movie_in_m78";
        var subject_2 = "lib_movie_subtitle_en_in_m78";
        var subject_3 = "lib_movie_subtitle_cn_in_m78";
        //列表-对话框-表单
        var tableId_1 = 'table_' + subject_1;
        var tableId_2 = 'table_' + subject_2;
        var tableId_3 = 'table_' + subject_3;

        var searchInputId_1 = 'search_input_' + subject_1;
        var searchInputId_2 = 'search_input_' + subject_2;
        var searchInputId_3 = 'search_input_' + subject_3;

        var tableObject_1 = $('#' + tableId_1);
        var tableObject_2 = $('#' + tableId_2);
        var tableObject_3 = $('#' + tableId_3);

        var addDialogId_1 = '#dialog_add_' + subject_1;
        var addDialogId_2 = '#dialog_add_' + subject_2;
        var addDialogId_3 = '#dialog_add_' + subject_3;
        var editDialogId_2 = '#dialog_edit_' + subject_2;
        var editDialogId_3 = '#dialog_edit_' + subject_3;

        var addFormId_1 = '#form_add_' + subject_1;
        var addFormId_2 = '#form_add_' + subject_2;
        var addFormId_3 = '#form_add_' + subject_3;
        var editFormId_2 = '#form_edit_' + subject_2;
        var editFormId_3 = '#form_edit_' + subject_3;

        var paramDataAdd_1 = {};
        var paramDataAdd_2 = {};
        var paramDataAdd_3 = {};
        var paramDataEdit_2 = {};
        var paramDataEdit_3 = {};

        var selectLeftMainId = 0;
        var configDialogAdd_1 = {
            href:'/admin/DatagridCustom/pageAdd',
            title:'新增数据表',
            queryParams:{},
            width:dialogDefaultWidth,
            height:dialogDefaultHeight,
            modal:true,
            buttons:[{
                text:'<i class="fa fa-check fa-btn-cls" style="color:green"></i>保存',
                plain:true,
                handler:function(){
                    paramDataAdd_1 = $(addFormId_1).serializeObject();
                    if(!paramDataAdd_1.datagrid_name){
                        layer.msg("请填写数据表名称");
                        return ;
                    }

                    if(!paramDataAdd_1.menu_id){
                        layer.msg("请选择菜单");
                        return ;
                    }
                    if(!paramDataAdd_1.table_id){
                        layer.msg("请选择数据表");
                        return ;
                    }

                    var loading = layer.load(1, {
                        shade: [0.1,'#fff'] //0.1透明度的白色背景
                    });
                    $.ajax({
                        url: '/api/DatagridCustom/addDatagridCustom',
                        async: false,
                        dataType:'json',
                        type:'post',
                        data:paramDataAdd_1,
                        success:function(resp){
                            layer.close(loading);
                            if( 1 == resp.code ){
                                $(addDialogId_1).dialog('close');
                                $(tableId_1).datagrid('reload');
                            }else{
                                layer.msg(resp.message);
                            }
                        }
                    });
                }
            },{
                text:'<i class="fa fa-times fa-btn-cls" style="color:red"></i>取消',
                plain:true,
                handler:function(){
                    $(addDialogId_1).dialog('close');
                }
            }]
        };

        var configDialogAdd_2 = {
            href:'/admin/DatagridColumn/pageAdd',
            title:'新增页面纵列',
            queryParams:{},
            width:dialogDefaultWidth,
            height:dialogDefaultHeight,
            modal:true,
            buttons:[{
                text:'<i class="fa fa-check fa-btn-cls" style="color:green"></i>保存',
                plain:true,
                handler:function(){
                    paramDataAdd_2 = $(addFormId_2).serializeObject();
                    paramDataAdd_2 = $.extend(paramDataAdd_2, {datagrid_id:selectLeftMainId});
                    console.log(paramDataAdd_2);
                    if(!paramDataAdd_2.column_name){
                        layer.msg("请填写列标识码");
                        return ;
                    }
                    if(!paramDataAdd_2.column_title){
                        layer.msg("请填写列名");
                        return ;
                    }
                    var loading = layer.load(1, {
                        shade: [0.1,'#fff'] //0.1透明度的白色背景
                    });
                    $.ajax({
                        url: '/api/DatagridColumn/addDatagridColumn',
                        async: false,
                        dataType:'json',
                        type:'post',
                        data:paramDataAdd_2,
                        success:function(resp){
                            layer.close(loading);
                            if( 1 == resp.code ){
                                $(addDialogId_2).dialog('close');
                                $(tableId_2).datagrid('reload');
                            }else{
                                layer.msg(resp.message);
                            }
                        }
                    });
                }
            },{
                text:'<i class="fa fa-times fa-btn-cls" style="color:red"></i>取消',
                plain:true,
                handler:function(){
                    $(addDialogId_2).dialog('close');
                }
            }]
        };
        var configDialogAdd_3 = {
            href:'/admin/DatagridToolbar/pageAdd',
            title:'新增页面工具栏',
            queryParams:{},
            width:dialogDefaultWidth,
            height:dialogDefaultHeight,
            modal:true,
            buttons:[{
                text:'<i class="fa fa-check fa-btn-cls" style="color:green"></i>保存',
                plain:true,
                handler:function(){
                    paramDataAdd_3 = $(addFormId_3).serializeObject();
                    paramDataAdd_3 = $.extend(paramDataAdd_3, {datagrid_id:selectLeftMainId});
                    console.log(paramDataAdd_3);
                    if(!paramDataAdd_3.button_type){
                        layer.msg("请填写类型");
                        return ;
                    }
                    if(!paramDataAdd_3.button_text){
                        layer.msg("请填写名称");
                        return ;
                    }
                    var loading = layer.load(1, {
                        shade: [0.1,'#fff'] //0.1透明度的白色背景
                    });
                    $.ajax({
                        url: '/api/DatagridToolbar/addPageToolbar',
                        async: false,
                        dataType:'json',
                        type:'post',
                        data:paramDataAdd_3,
                        success:function(resp){
                            layer.close(loading);
                            if( 1 == resp.code ){
                                $(addDialogId_3).dialog('close');
                                tableObject_3.datagrid('reload');
                            }else{
                                layer.msg(resp.message);
                            }
                        }
                    });
                }
            },{
                text:'<i class="fa fa-times fa-btn-cls" style="color:red"></i>取消',
                plain:true,
                handler:function(){
                    $(addDialogId_3).dialog('close');
                }
            }]
        };
        var configDialogEdit = {
            href:'role/edit',
            title:'修改角色',
            queryParams:{},
            width:dialogDefaultWidth,
            height:dialogDefaultHeight,
            modal:true,
            buttons:[{
                text:'<i class="fa fa-check fa-btn-cls" style="color:green"></i>保存',
                plain:true,
                handler:function(){
                    paramDataEdit = $(editFormId).serializeObject();
                    console.log(paramDataEdit);
                    if(!paramDataEdit.role_name){
                        layer.msg("请填写角色名称");
                        return ;
                    }
                    var loading = layer.load(1, {
                        shade: [0.1,'#fff'] //0.1透明度的白色背景
                    });
                    $.ajax({
                        url: '/api/role/edit',
                        async: false,
                        dataType:'json',
                        type:'post',
                        data:paramDataEdit,
                        success:function(resp){
                            layer.close(loading);
                            if( 1 == resp.code ){
                                $(editDialogId).dialog('close');
                                $(tableId).datagrid('reload');
                            }else{
                                layer.msg(resp.message);
                            }
                        }
                    });
                }
            },{
                text:'<i class="fa fa-times fa-btn-cls" style="color:red"></i>取消',
                plain:true,
                handler:function(){
                    $(editDialogId).dialog('close');
                }
            }]
        };
        var configDialogEdit_3 = {
            href:'/admin/DatagridToolbar/pageEdit',
            title:'编辑页面工具栏',
            queryParams:{},
            width:dialogDefaultWidth,
            height:dialogDefaultHeight,
            modal:true,
            buttons:[{
                text:'<i class="fa fa-check fa-btn-cls" style="color:green"></i>保存',
                plain:true,
                handler:function(){
                    paramDataEdit_3 = $(editFormId_3).serializeObject();
                    console.log(paramDataEdit_3);
                    if(!paramDataEdit_3.button_type){
                        layer.msg("请填写类型");
                        return ;
                    }
                    if(!paramDataEdit_3.button_text){
                        layer.msg("请填写名称");
                        return ;
                    }
                    var loading = layer.load(1, {
                        shade: [0.1,'#fff'] //0.1透明度的白色背景
                    });
                    $.ajax({
                        url: '/api/DatagridToolbar/editPageToolbar',
                        async: false,
                        dataType:'json',
                        type:'post',
                        data:paramDataEdit_3,
                        success:function(resp){
                            layer.close(loading);
                            if( 1 == resp.code ){
                                $(editDialogId_3).dialog('close');
                                tableObject_3.datagrid('reload');
                            }else{
                                layer.msg(resp.message);
                            }
                        }
                    });
                }
            },{
                text:'<i class="fa fa-times fa-btn-cls" style="color:red"></i>取消',
                plain:true,
                handler:function(){
                    $(editDialogId_3).dialog('close');
                }
            }]
        };

        var configDatagrid_1 = {
            url:'/api/LibMovie/getLibMovieList',
            method: 'post',
            remoteSort:false,
            queryParams:{},
            pageList:[25,50,100],
            pageSize:25,
            pagination:true,
            clickToEdit:false,
            dblclickToEdit:false,
            singleSelect:true,
            checkOnSelect:true,
            selectOnCheck:true,
            rownumbers:false,
            striped:true,
            fitColumns:true,
            fit:true,
            frozenColumns:[[
            ]],
            columns:[[
                {field:'id',title:'ID',width:40,hidden:true},
                {field:'movie_name_cn',title:'片名', width:100},
            ]],
            loadFilter: function(data){
                return loadFilter(data, true);
            },
            onSelect: function(index, row){
                configDatagrid_2.queryParams = {movie_id:row.id, subtitle_lang: 'en'};
                tableObject_2.datagrid(configDatagrid_2);
                SearchCombobox(searchInputId_2, tableId_2,function (val,name) {
                    configDatagrid_2.queryParams[name] = val;
                    tableObject_2.datagrid(configDatagrid_2);
                },['ID', '序号']);

                configDatagrid_3.queryParams = {movie_id:row.id, subtitle_lang: 'cn'};
                tableObject_3.datagrid(configDatagrid_3);
                SearchCombobox(searchInputId_3, tableId_3,function (val,name) {
                    configDatagrid_3.queryParams[name] = val;
                    configDatagrid_3.datagrid(configDatagrid_3);
                },['ID', '序号']);
                selectLeftMainId = row.id;
            },
            onClickRow: function(index, row){
                // console.log("enter click row");
                // selectLeftMainId = row.id;
                // configDatagrid_2.queryParams = {datagrid_id:row.id};
                // tableObject_2.datagrid(configDatagrid_2);
            },
            onCheck: function(index, row){
            },
            onUncheck: function(index, row){
            },
            onLoadSuccess: function(){
                tableObject_1.datagrid('selectRow', 0);
                $(".datagrid-header-check").html("");
            },
            toolbar:[
                {
                    text:'<span class="tool-btn-refresh"><i class="fa fa-refresh"></i>刷新</span>',
                    plain:true,
                    handler:function(){
                        tableObject_1.datagrid('reload');
                    }
                },
                {
                    text:'<span class="tool-btn-add"><i class="fa fa-plus"></i>新增</span>',
                    plain:true,
                    handler:function(){
                        $(addDialogId_1).dialog(configDialogAdd_1);
                    }
                }
            ]

        };
        var configDatagrid_2 = {
            url:'/api/LibMovieSubtitle/getLibMovieSubtitleList',
            method: 'post',
            remoteSort:false,
            queryParams:{subtitle_lang:'en'},
            pageList:[30,50,100],
            pageSize:30,
            pagination:true,
            clickToEdit:false,
            dblclickToEdit:true,
            singleSelect:false,
            checkOnSelect:false,
            selectOnCheck:false,
            rownumbers:false,
            striped:true,
            frozenColumns:[[
            ]],
            columns:[[
                {field:'id',title:'ID',width:40,hidden:true},
                {field:'seq_index',title:'序号', width:80},
                {field:'subtitle',title:'字幕', width:800},
            ]],
            loadFilter: function(data){
                return loadFilter(data, true);
            },
            onCheck: function(row){
            },
            onUncheck: function(row){
            },
            onEndEdit: function(index, row, changes) { //在完成编辑但编辑器还没有销毁之前触发
                console.log("end edit:", index, row);
                if (JSON.stringify(changes) != '{}') {
                    var updateData = $.extend({id:row.id}, changes);
                    $.ajax({
                        url:'/api/DatagridColumn/simpleUpdateDatagridColumn',
                        type:'post',
                        data: updateData,
                        dataType:'json',
                        async:false,
                        success:function(resp){
                            if(0 == resp.code){
                                layer.msg(resp.message);
                            }else{
                                //tableObject_2.datagrid('updateRow', index);
                                tableObject_2.datagrid('reload');
                            }
                        }
                    });
                }
            },
            onLoadSuccess:function(){
            },
            toolbar:[
                {
                    text:'<span class="tool-btn-refresh"><i class="fa fa-refresh"></i>刷新</span>',
                    plain:true,
                    handler:function(){
                        tableObject_2.treegrid('reload');
                    }
                },
                {
                    text:'<span class="tool-btn-add"><i class="fa fa-plus"></i>新增</span>',
                    plain:true,
                    handler:function(){
                        $(addDialogId_2).dialog(configDialogAdd_2);
                    }
                },
                {
                    text:'<span class="tool-btn-edit"><i class="fa fa-pencil"></i>编辑</span>',
                    plain:true,
                    handler:function(){
                        tableObject_1.datagrid('reload');
                    }
                },
                {
                    text:'<span class="tool-btn-delete"><i class="fa fa-trash"></i>删除</span>',
                    plain:true,
                    handler:function(){
                        tableObject_1.datagrid('reload');
                    }
                }
            ]

        };
        var configDatagrid_3 = {
            url:'/api/LibMovieSubtitle/getLibMovieSubtitleList',
            method: 'post',
            remoteSort:false,
            queryParams:{subtitle_lang:'cn'},
            pageList:[30,50,100],
            pageSize:30,
            pagination:true,
            clickToEdit:false,
            dblclickToEdit:true,
            singleSelect:false,
            checkOnSelect:false,
            selectOnCheck:false,
            rownumbers:false,
            striped:true,
            frozenColumns:[[
            ]],
            columns:[[
                {field:'id',title:'ID',width:40,hidden:true},
                {field:'seq_index',title:'序号', width:80},
                {field:'subtitle',title:'字幕', width:800},
            ]],
            loadFilter: function(data){
                return loadFilter(data, true);
            },
            onCheck: function(row){
            },
            onUncheck: function(row){
            },
            onEndEdit: function(index, row, changes) { //在完成编辑但编辑器还没有销毁之前触发
                console.log("end edit:", index, row);
                if (JSON.stringify(changes) != '{}') {
                    var updateData = $.extend({id:row.id}, changes);
                    $.ajax({
                        url:'/api/DatagridColumn/simpleUpdateDatagridColumn',
                        type:'post',
                        data: updateData,
                        dataType:'json',
                        async:false,
                        success:function(resp){
                            if(0 == resp.code){
                                layer.msg(resp.message);
                            }else{
                                //tableObject_2.datagrid('updateRow', index);
                                tableObject_2.datagrid('reload');
                            }
                        }
                    });
                }
            },
            onLoadSuccess:function(){
            },
            toolbar:[
                {
                    text:'<span class="tool-btn-refresh"><i class="fa fa-refresh"></i>刷新</span>',
                    plain:true,
                    handler:function(){
                        tableObject_2.treegrid('reload');
                    }
                },
                {
                    text:'<span class="tool-btn-add"><i class="fa fa-plus"></i>新增</span>',
                    plain:true,
                    handler:function(){
                        $(addDialogId_2).dialog(configDialogAdd_2);
                    }
                },
                {
                    text:'<span class="tool-btn-edit"><i class="fa fa-pencil"></i>编辑</span>',
                    plain:true,
                    handler:function(){
                        tableObject_1.datagrid('reload');
                    }
                },
                {
                    text:'<span class="tool-btn-delete"><i class="fa fa-trash"></i>删除</span>',
                    plain:true,
                    handler:function(){
                        tableObject_1.datagrid('reload');
                    }
                }
            ]

        };
        tableObject_1.datagrid(configDatagrid_1);
        tableObject_3.datagrid(configDatagrid_3);

        SearchCombobox(searchInputId_1, tableId_1,function (val,name) {
            configDatagrid_1.queryParams = {};
            configDatagrid_1.queryParams[name] = val;
            tableObject_1.datagrid(configDatagrid_1);
        },['ck','ID']);

        SearchCombobox(searchInputId_3, tableId_3,function (val,name) {
            configDatagrid_3.queryParams = {};
            configDatagrid_3.queryParams[name] = val;
            tableObject_3.datagrid(configDatagrid_3);
        },['ck','ID']);

        function togglePageToolbar(pageToolbarId, fieldName, value)
        {
            console.log("update page toolbar", pageToolbarId);
            $.ajax({
                url:'/api/DatagridToolbar/toggleDatagridToolbar',
                type:'post',
                data: {id: pageToolbarId, field_name: fieldName, value:value},
                dataType:'json',
                async:false,
                success:function(resp){
                    if(0 == resp.code){
                        layer.msg(resp.message);
                    }
                }
            });
        }

    });

</script>